<?php

/*

	MMetaverse - Open Metaverse Access Library

	Copyright (c) 2009 Mary Jane Soft - Marlon J. Manrique

	http://www.maryjanesoft.com
	http://www.marlonj.com

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General
	Public License along with this library; if not, write to the
	Free Software Foundation, Inc., 59 Temple Place, Suite 330,
	Boston, MA  02111-1307  USA

	$Id$

*/

/**
 * @package mjs.mmetaverse.manager
 */

/**
 * Region Manager
 */
class MRegionManager {

    /**
     * DataBase
     */
    private $db;

    /**
     * Create a Region Manager
     *
     * @param MMetaverse $metaverse Current Metaverse
     */
    function MRegionManager(MMetaverse $metaverse) {
        $this->db = $metaverse->getDataBase('region');
    }

    /**
     * Returns an array with all the regions available in the grid
     *
     * @return MRegion[] Current regions
     */
    public function getRegions() {
        return $this->db->getRegions();
    }

    /**
     * Return the number of regions in the grid
     *
     * @return number of regions
     */
    public function getNumberOfRegions() {
        return $this->db->getNumberOfRegions();
    }

    /**
     * Return the region with the uuid specified
     *
     * @param MUUID uuid Region UUID
     * @return MRegion Region information
     */
    public function getRegion(MUUID $uuid) {
        return $this->db->getRegion($uuid);
    }

    /**
     * Return the URI for the region with the uuid specified
     * 
     * @param MUUID uuid Region UUID
     */
    public function getRegionImageURI(MUUID $uuid) {
        // Get region information
        $region = $this->getRegion($uuid);

        // Get Server and port information 
        $serverIP = $region->getServerIP();
        $serverHttpPort = 9000;

        // Create URI
        $imageURI = 'http://' . $serverIP . ':' . $serverHttpPort .
            '/index.php?method=regionImage' . $uuid->getUnHyphenated();

        // Return the image uri
        return $imageURI;
    }
}

?>
